cmake_minimum_required(VERSION 3.5)

project(dal_fastdds)


if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR  MATCHES "aarch64")
else()
    find_package(tinyxml2 REQUIRED)
endif()

include_directories(${PROJECT_SOURCE_DIR}/include)

set (SOURCES
    src/dal/version.cpp
    src/dal/identifier.cpp
    src/dal/config_loader.cpp
    src/dal/utils.c
    src/dal/allocator.c
    src/dal_entity/domain_participant.cpp
    src/dal_entity/topic.cpp
    src/dal_entity/publisher.cpp
    src/dal_entity/subscriber.cpp
    src/dal_entity/service.cpp
    src/dal_entity/client.cpp
    src/converter/StatusConverter.cpp
    src/converter/StatusMaskConverter.cpp
    src/converter/QosConverter.cpp
    src/converter/SampleInfoConverter.cpp
    src/converter/RetTypeConverter.cpp
    src/converter/InstanceHandleConverter.cpp
    src/converter/GuidConverter.cpp
    src/converter/WriteParamsConverter.cpp
    src/converter/LocatorKindConverter.cpp
    src/listener_impl/DomainParticipantListenerImpl.cpp
    src/listener_impl/PublisherListenerImpl.cpp
    src/listener_impl/SubscriberListenerImpl.cpp
    src/listener_impl/TopicListenerImpl.cpp
    src/listener_impl/DataWriterListenerImpl.cpp
    src/listener_impl/DataReaderListenerImpl.cpp
    src/listener_impl/ClientRespReaderListenerImpl.cpp
    src/listener_impl/ClientReqWriterListenerImpl.cpp
    src/listener_impl/ServiceReqReaderListenerImpl.cpp
    src/entity_impl/DalDomainParticipantImpl.cpp
    src/entity_impl/DalPublisherImpl.cpp
    src/entity_impl/DalSubscriberImpl.cpp
    src/entity_impl/DalTopicImpl.cpp
    src/entity_impl/DalDataWriterImpl.cpp
    src/entity_impl/DalDataReaderImpl.cpp
    src/entity_impl/DalServiceImpl.cpp
    src/entity_impl/DalClientImpl.cpp
    src/utils/StringUtils.cpp
    src/utils/EntityMappingManager.cpp
    src/utils/TopicAndTypeHelper.cpp
    src/rtps/Guid.cpp
    src/rtps/GuidUtils.cpp
    src/config_manager/ConfigManager.cpp
)

set(INCLUDE_DIRS
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dcutils
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dcpputils
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl/dalidl_runtime_cpp
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl_typesupport
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl_typesupport_interface
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl_typesupport_fastrtps
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dalidl_typesupport_introspection
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dal
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dal_fastrtps
    ${PROJECT_SOURCE_DIR}/../dal_msg/include/dal_fastrtps/dal_fastrtps_cpp
)

if (DAL_ENABLE_DMABUFHEAP)
    list(APPEND SOURCES
        src/dbh/DalDbhWriter.cpp
        src/dbh/DalDbhBestEffortWriter.cpp
        src/dbh/DalDbhReliableWriter.cpp
        src/dbh/DalDbhReader.cpp
        src/dbh/DalDbhBestEffortReader.cpp
        src/dbh/DalDbhReliableReader.cpp
        src/listener_impl/DataWriterListenerImplDbhExtend.cpp
        src/listener_impl/DataReaderListenerImplDbhExtend.cpp
        src/listener_impl/DataReaderListenerImplDbhInfo.cpp
        ../dal_dmabufheap/src/DmaBufHeapManager.cpp
        ../dal_dmabufheap/src/DmaBufHeapTopicSelector.cpp
        ../dal_dmabufheap/src/FdStrConverter.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_cpp/dal_builtin/msg/dal_dma_buf_heap_recv_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_cpp/dal_builtin/msg/dal_dma_buf_heap_send_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_cpp/dal_builtin/msg/dal_dma_buf_heap_info__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_fastrtps_cpp/dal_builtin/msg/detail/dds_fastrtps/dal_dma_buf_heap_recv_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_fastrtps_cpp/dal_builtin/msg/detail/dds_fastrtps/dal_dma_buf_heap_send_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_fastrtps_cpp/dal_builtin/msg/detail/dds_fastrtps/dal_dma_buf_heap_info__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_introspection_cpp/dal_builtin/msg/detail/dal_dma_buf_heap_recv_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_introspection_cpp/dal_builtin/msg/detail/dal_dma_buf_heap_send_notify_msg__type_support.cpp
        ../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_introspection_cpp/dal_builtin/msg/detail/dal_dma_buf_heap_info__type_support.cpp
    )

    list(APPEND INCLUDE_DIRS
        ${PROJECT_SOURCE_DIR}/../dal_dmabufheap/include
        ${PROJECT_SOURCE_DIR}/../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_generator_cpp
        ${PROJECT_SOURCE_DIR}/../dal_dmabufheap/dmabufheap_typesupport/dal_builtin/dalidl_typesupport_fastrtps_cpp
        ${PROJECT_SOURCE_DIR}/../thirdpart/json/include
        "$ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/hanhai/"
    )
endif()

add_library(dal_fastdds SHARED ${SOURCES})
target_include_directories(dal_fastdds PRIVATE ${INCLUDE_DIRS})
target_link_libraries(dal_fastdds PUBLIC 
    dal_typesupport_fastdds_depends dal_utils fastrtps tinyxml2 dl)

if (DAL_ENABLE_DMABUFHEAP)
target_link_libraries(dal_fastdds PUBLIC dmabufheap)
endif()

add_subdirectory(test)

install(TARGETS dal_fastdds
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

get_property( dal_fastdds_version GLOBAL PROPERTY dal_fastdds_version )
set_property(
    TARGET dal_fastdds
    PROPERTY VERSION ${dal_fastdds_version}
)
target_compile_definitions(dal_fastdds PRIVATE LIB_VERSION=\"Version:${dal_fastdds_version}\")
